<html>
<head>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link href="${ctx}/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link href="${ctx}/font-awesome/3.0.0/css/font-awesome.min.css" rel="stylesheet">
    <link href="${ctx}/css/index.css" rel="stylesheet">
    <!-- font -->
    <link href="${ctx}/font-awesome/3.0.0/css/font-awesome.min.css" rel="stylesheet">
    <link href="${ctx}/bootstrap-table/1.12.0/bootstrap-table.min.css" rel="stylesheet">
    <script src="${ctx}/jquery/2.1.4/jquery.min.js"></script>
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="${ctx}/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/bootstrap-table.min.js"></script>
    <script src="${ctx}/layui/layui.all.js"></script>
    <link href="${ctx}/layui/css/layui.css" rel="stylesheet">
    <script src="${ctx}/js/util.js"></script>
</head>
<style>
    .layui-form-checkbox[lay-skin=primary] i {
        top: 5px;
    }
</style>
<body>
<div class="container-fluid">
    <form class="layui-form" action="" style="margin-top: 10px">
        <div class="input-group" style="float: left; width: 300px; margin-right:20px;">
            <span class="input-group-addon">手机号</span>
            <input type="text" class="form-control" id="phone">
        </div>
        <div class="layui-inline">
            <label class="layui-form-label" style="width: 120px">提现起始时间</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="star" placeholder="请选择时间">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label" style="width: 120px">提现结束时间</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="end" placeholder="请选择时间">
            </div>
        </div>

        <div style="width: 150px;display: inline-block;margin-left: 20px">
            <select name="checkStatus" id="checkStatus" lay-verify="" style="width:300px">
                <option value="">审核状态</option>
                <option value="3">审核成功</option>
                <option value="2">财务待审核</option>
                <option value="1">业务员待审核</option>
                <option value="-1">审核失败</option>

            </select>
        </div>
        <span id="search_btn" class="btn btn-info" style="height: 38px;margin-left: 10px;font-size: 14px">查询</span>
    </form>

    <table class="table table-border table-bordered table-hover table-bg table-sort" id="layTable"
           lay-filter="tableFilter">

    </table>

    <script src="${ctx}/bootstrap-table/1.12.0/locale/bootstrap-table-zh-CN.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/extensions/export/bootstrap-table-export.min.js"></script>
    <script src="${ctx}/js/extends.js"></script>
    <script type="text/html" id="barDemo">

        <a class="layui-btn layui-btn-xs " lay-event="xbls">新版流水</a>
        <a class="layui-btn layui-btn-xs " lay-event="lsjl">流水</a>
        <a class="layui-btn layui-btn-xs " lay-event="rwjl">任务记录</a>
    </script>
    <script>
        var phone = "";
        var star = "";
        var end = "";
        var remittance = "";
        var check_status = "";
        var status = ""
        layui.use('laydate', function () {
            var laydate = layui.laydate;
            laydate.render({
                elem: '#star'
                , type: 'datetime'

            });
            laydate.render({
                elem: '#end'
                , type: 'datetime'

            });
        });
        layui.use('form', function () {
            var form = layui.form;
            form.render();
            //监听提交
            form.on('submit(formDemo)', function (data) {
                layer.msg(JSON.stringify(data.field));
                return false;
            });
        });
        layui.use('table', function () {
            tableIns = layui.table;
            form = layui.form;
            tableIns.render({
                elem: '#layTable'

                ,
                url: '/sys/membercashwithdrawal/staff-getList'
                ,
                method: 'POST'
                ,
                toolbar: true


                ,
                id: 'dataTableId'
                ,
                cols: [[
                    {
                        type: 'checkbox', field: 'id'
                    }
                    , {
                        field: 'amount',
                        title: '申请提现(元)',
                        width: 160,
                        align: 'center',
                        sort: true,
                        templet: function (data) {
                            return (data.amount / 100) + '元';
                        }
                    }
                    , {
                        field: 'createTime',
                        title: '申请提现时间',
                        width: 150,
                        align: 'center',
                        sort: true,
                        templet: function (data) {
                            return dateFormat(data.create_time);
                        }
                    }


                    , {
                        field: 'method', title: '提现方式', width: 100, align: 'center', sort: true,
                        templet: function (data) {
                            if (data.method === 1) {
                                return "<div style='color: blue'>支付宝<div> ";
                            } else if (data.method === 2) {
                                return "<div style='color: red'>微信<div> ";
                            } else {
                                return "-";
                            }

                        }
                    }
                    , {
                        field: 'status', title: '订单状态', width: 100, align: 'center', sort: true,
                        templet: function (data) {
                            if (data.check_status === 3) {
                                return "<div style='color: blue'>已到账<div> ";
                            } else if (data.check_status === 1) {
                                return "<div style='color: red'>业务员待审<div> ";
                            } else if (data.check_status === -1) {
                                return "<div style='color: red'>审核失败<div> ";
                            } else if (data.check_status === 2) {
                                return "<div style='color: red'>财务待审<div> ";
                            } else {
                                return data.check_status;
                            }

                        }
                    }

                    , {
                        field: 'payType', title: '最终打款方式', width: 100, align: 'center', sort: true,
                        templet: function (data) {
                            if (data.payType === undefined) {
                                return "<div style='color: blue'>待处理<div> ";
                            }
                            if (data.payType === 1) {
                                return "<div style='color: blue'>支付宝<div> ";
                            } else if(data.payType === 2){
                                return "<div style='color: red'>微信<div> ";
                            }else {
                                return "<div style='color: red'>人工<div> ";
                            }

                        }
                    }
                    , {
                        field: 'phone', title: '手机号', width: 120, align: 'center', sort: true
                    }
                    , {
                        field: 'content', title: '年龄/性别/账户/真实姓名', width: 200, align: 'center', sort: true,
                        templet: function (data) {

                            if (data.amount > 1000) {
                                return (data.birthday+':'+data.sex+':'+data.trade_account + ':' + data.real_name);
                            } else {

                                return '<span style="color:red">' + (data.birthday+':'+data.sex+':'+data.trade_account + ':' + data.real_name) + '</span>';
                            }
                        }
                    }

                    , {
                        field: 'totalAmount',
                        title: '用户总收益(元)',
                        width: 160,
                        align: 'center',
                        sort: true,
                        templet: function (data) {
                            var value = data.totalAmount;
                            value = value / 100;
                            var a = '<a onClick="details(\'' + data.memberId + '\')">' + value + '元</a>';
                            return a;
                        }
                    }
                    , {
                        field: 'oldAmount',
                        title: '历史提现(元)',
                        width: 160,
                        align: 'center',
                        sort: true,
                        templet: function (data) {
                            return (data.oldAmount / 100) + '元';
                        }
                    }
                    , {
                        field: 'create_by',
                        title: '账户余额',
                        width: 160,
                        align: 'center',
                        sort: true,
                        templet: function (data) {
                            return (data.money / 100) + '元';
                        }
                    }


                    , {
                        field: 'c', title: '提现次数（成功/失败）', width: 150, align: 'center', templet: function (data) {

                            var str = '<font style="color: green">' + data.successcount + '/</font>';
                            str += '<font style="color: red">' + data.failcount + '</font>';
                            return str;
                        }
                    }
                    , {
                        field: 'c', title: '其他信息', width: 160, align: 'center', templet: function (data) {
                            var str = data.ip + "/" + data.mac + "/" + data.imei
                            return str;
                        }
                    }, {
                        field: 'trade_no', title: '订单号', width: 200, align: 'center', sort: true
                    }, {
                        field: 'icard', title: '身份证', width: 160, align: 'center', sort: true
                    }, {
                        field: 'code_addr', title: '地区', width: 160, align: 'center', sort: true
                    }, {
                        field: 'birthday', title: '年龄', width: 50, align: 'center', sort: true
                    }  , {
                        field: '', title: '审核时间', width: 150, align: 'center', sort: true,
                        templet: function (data) {
                            return dateFormat(data.trade_time);
                        }
                    }
                    , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 250, align: 'center'}

                ]]
                ,
                page: true
            });
            $("#search_btn").click(function () {
                reload();

            });

            form.on('switch(sexDemo)', function (obj) {
                // layer.tips(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis);
                if (obj.elem.checked) {
                    commonenable(this.value, 'False');
                } else {
                    commonenable(this.value, 'true');
                }

            });
            tableIns.on('checkbox(tableFilter)', function (obj) {
                var checkStatus = tableIns.checkStatus('dataTableId');
                var dataList = checkStatus.data;
                if (dataList != null && dataList.length > 0) {

                    for (var i = 0; i < dataList.length; i++) {
                        ids += dataList[i].id + ",";
                    }
                }
            });

            function deleteId(ids) {
                if (ids != "") {
                    $.ajax({
                        url: "/delete/data",
                        type: 'post',
                        data: {"table": table, "ids": ids},
                        async: false,
                        dataType: "json",
                        success: function (arg) {
                            if (arg) {
                                layer.msg(arg.message);
                                reload();
                            } else {
                                layer.msg(arg.message);
                            }
                        }
                    });
                }
            }

            $("#multiDelete").click(function () {
                deleteId(ids)
            });

            tableIns.on('tool(tableFilter)', function (obj) {
                var data = obj.data;
                if (obj.event === 'detail') {
                    layer.msg('ID：' + data.id + ' 的查看操作');
                } else if (obj.event === 'del') {
                    if (data.has_deleted == 1) {
                        layer.msg('已删除，不可进行该操作!', {icon: 1, time: 1000});
                        return;
                    }
                    layer.confirm('真的删除行么', function (index) {
                        deleteId(data.id)
                        layer.close(index);
                    });
                } else if (obj.event === 'edit') {
                    if (data.has_deleted == 1) {
                        layer.msg('已删除，不可进行该操作!', {icon: 1, time: 1000});
                        return;
                    }
                    layer_show("修改", "/financeRecord/edit?id=" + data.id, "550", "650");
                    parent.search();
                } else if (obj.event === 'rwjl') {
                    records(data.memberId)
                } else if (obj.event === 'shenhe') {
                    layer.confirm('请审核', {
                        btn: ['通过', '拒绝', '取消'] //可以无限个按钮
                        , btn3: function (index, layero) {
                            //按钮【按钮三】的回调
                            layer.close(index);
                        }
                    }, function (index, layero) {
                        layer.close(index);
                        //按钮【按钮一】的回调
                        pass(data.id);
                    }, function (index) {
                        layer.close(index);
                        //按钮【按钮二】的回调
                        repulse(data.id);
                    });
                } else if (obj.event === 'lsjl') {
                    details(data.memberId)
                } else if (obj.event === 'xbls') {
                    xbls(data.memberId)
                }
            });
        });

        function queryParams(opt) {
            opt.search = $("#search").val();
            opt.order = 'desc';
            return opt;
        };

        var table = null;


        // 通过
        var pass = function (id) {

            $.post("/sys/membercashwithdrawal/pass", {
                'id': id
            }, function (res) {
                if (res.success) {
                    layer.msg(res.message);
                    reload();
                } else {
                    layer.msg(res.message);
                }


            });

        };

        // 拒绝
        var repulse = function (id) {
            var remark = prompt("输入原因", "");
            if (remark != null && remark != "") {
                if (confirm("确定拒绝？")) {
                    $.post("/sys/membercashwithdrawal/repulse", {
                        'id': id,
                        'remark': remark
                    }, function (res) {
                        if (res.success) {
                            layer.msg(res.message);
                            reload();
                        } else {
                            layer.msg(res.message);
                        }


                    });
                }
            }
        };

        // 任务
        var records = function (memberId) {
            var id = 'record_list';
            var title = '任务详情';
            var href = '/member/recordList/' + memberId;
            if (id) {
                window.parent.iw.dialog({
                    size: 'lg',
                    id: id,
                    title: title,
                    href: href
                });
            }
        };

        // 流水
        var details = function (memberId) {
            var id = 'trade_list';
            var title = '收支明细';
            var href = '/member/tradeList/' + memberId;
            if (id) {
                window.parent.iw.dialog({
                    size: 'lg',
                    id: id,
                    title: title,
                    href: href
                });
            }
        };
        // 流水
        var xbls = function (memberId) {
            var id = 'xbls' + memberId;
            var title = '收支明细';
            var href = '/sys/membernewtrade/list?memberId=' + memberId;
            if (id) {
                window.parent.iw.dialog({
                    size: 'lg',
                    id: id,
                    title: title,
                    href: href
                });
            }
        };

        function reload() {
            checkStatus = $("#checkStatus").val();
            status = $("#status").val();
            star = $("#star").val();
            end = $("#end").val();
            phone = $("#phone").val();
            tableIns.reload('dataTableId', {
                where: {

                    checkStatus: checkStatus
                    , status: status
                    , star: star
                    , end: end
                    , phone: phone
                }
                , page: {
                    curr: 1
                }
            });
        }

        function txbc() {
            var txbc = $("#txbc").val();
            $.ajax({
                url: "/sys/membercashwithdrawal/bucangtixian",
                type: 'post',
                data: {"memberId": txbc},
                async: false,
                dataType: "json",
                success: function (arg) {
                    if (arg) {
                        layer.msg(arg.message);
                        reload();
                    } else {
                        layer.msg(arg.message);
                    }
                }
            });
        }
    </script>
</body>
</html>